{template 'common/header'}
<title>余额提现</title>
<div id="container"></div>

<script id="tpl_main" type="text/html">
	<div class="mui-content content-bg-w7">
		<div class="money-icon">

		</div>
		<div class="info-money">
			<div class="tittle-money">
				您的当前余额
			</div>
			<div class="money-detail" id="credit">
				￥<%credit%>
			</div>
		</div>
		<input type="text" name="" id="money" value="" placeholder="请输入提现的金额" class="input-recharge"/>
		<button type="button" class="mui-btn mui-btn-blue mui-btn-block btn-withdraw-wechat balance_sub1">确认提现</button>
		<a class="mui-btn mui-btn-purple mui-btn-block btn-withdraw-record" onclick="location.href='{php echo $this->createMobileUrl('member/log',array('type'=>1))}'">提现记录</a>
	</div>
</script>

<script language="javascript">
	require(['tpl', 'core'], function (tpl, core) {

		core.json('member/withdraw', {}, function (json) {

			var result = json.result;
			if (json.status != 1) {
				core.tip.show(json.result);
				return;
			}

			$('#container').html(tpl('tpl_main', result));

			if(result.noinfo){
				core.message('请补充您的资料后才能申请提现!',result.infourl,'warning');
				return;
			}

			var withdrawmoney = {php echo empty($set['trade']['withdrawmoney'])?0:floatval($set['trade']['withdrawmoney'])};

			if(result.credit<=0){
				core.message('无余额，无法申请提现!',"{php echo $this->createMobileUrl('member')}",'warning');
				return;
			}

			if(withdrawmoney>0 && result.credit<withdrawmoney){
				core.message('余额不足 '+ withdrawmoney +' 元，无法申请提现!',"{php echo $this->createMobileUrl('member')}",'warning');
				return;
			}


			$('.balance_sub1').click(function () {
				if ($(this).attr('submitting') == '1') {
					return;
				}
				var money = $('#money').val();
				if (!$('#money').isNumber()) {

					core.tip.show('请输入数字金额!');
					return;
				}
				if( parseFloat(money) < withdrawmoney){
					core.tip.show('满 '+ withdrawmoney +' 元才能申请提现!');
					return;
				}

				$(this).attr('submitting', 1);
				core.json('member/withdraw', {op: 'submit', money: money}, function (rjson) {
					if(rjson.status!=1){
						$(this).removeAttr('submitting');
						core.tip.show(rjson.result);
						return;
					}
					core.message('提现申请提交成功，请等待审核!',"{php echo $this->createMobileUrl('member')}",'success');
				}, true, true);

			});
		}, true);
	});

</script>

{template 'common/footer'}